﻿
#r "System.Windows.Forms.DataVisualization.dll"

open System
open System.Drawing // for Font
open System.Windows.Forms
open System.Windows.Forms.DataVisualization.Charting

type Point = {
    X : float
    Y1 : float
    Y2 : float
}

#load "Common.fsx"
open Common // since we didn't define top-level module, so use file name as the module name

let demoBindY chart =
    let line1 = addSeries chart SeriesChartType.Line
    let datas1 = 
        [
            for index = 1 to 100 do
                let x = float index
                yield (2.0 * sin(x/3.0) + cos(x/20.0))
        ]
    line1.BorderWidth <- 4
    line1.Points.DataBindY datas1

let demoBindXY chart =
    let line = addSeries chart SeriesChartType.Line
    let numbers = [1..100]
    let xs = numbers |> List.map (fun n->(float n)/4.0)
    let ys = numbers |> List.map (fun n-> 
                                        let x = float n
                                        5.0 * sin(x/30.0) + cos(x/2.0))
    line.BorderWidth <- 3
    line.Points.DataBindXY(xs,ys)

let demoBindXY_tuple chart = 
    let line = addSeries chart SeriesChartType.Line
    let points =
        [
            for index = 1 to 100 do
                let x = float index
                let y = 18.0 * sin(x/50.0) + cos(x/2.0)
                yield x,y
        ]
    line.BorderWidth <- 4
    line.Points.DataBindXY(points,"Item1",points,"Item2")

let demoBind_object chart = 
    // -------------- make datas
    let points = seq {
        for index = 1 to 100 do
            let x = float index
            let y1 = 18.0 * sin(x/30.0) + cos(x/2.0)
            let y2 = 6.0 * cos(x/25.0) + sin(x/3.0)
            yield {X=x;Y1 = y1;Y2=y2}
    }

    // -------------- draw the curve
    let line1 = addSeries chart SeriesChartType.Line
    line1.BorderWidth <- 4
    line1.Points.DataBind(points,"X","Y1","")
    
    let line2 = addSeries chart SeriesChartType.Line
    line2.BorderWidth <- 6
    line2.Points.DataBind(points,"X","Y2","")

let demoPieChart chart =
    let pie = addSeries chart SeriesChartType.Doughnut
    pie.Font <- new Font("Verdana", 12.0f)

    let values = [ 1033043; 4166741; 732759; 588649; 351659; 35838  ]
    let names  = [ "Africa"; "Asia"; "Europe"; "South America";
                   "North America"; "Oceania" ]
    pie.Points.DataBindXY(names,values)

let chart = makeChart() 
// demoBindY chart
// demoBindXY chart
// demoBindXY_tuple chart
demoBind_object chart
// demoPieChart chart
